/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.sprite.display;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObjectContainer;
import flash.geom.Point;
import hapi.sprite.sheet.CacheBitmapDataSpriteSheet;
import hapi.sprite.sheet.CopyPixelsSpriteSheet;
import hapi.sprite.sheet.DrawOnBitmapSpriteSheet;

class BitmapSpriteSheetDisplay extends Bitmap, implements SpriteSheetDisplay, implements Displayable {
	
	var dest:Point;
	public var currentFrame(default, null):Int;
	public var totalFrames(default, null):Int;
	
	function new(bitmapData:BitmapData, totalFrames:Int, ?x:Float=0.0, ?y:Float=0.0) {
		super(bitmapData);
		this.dest = new Point(0.0, 0.0);
		this.totalFrames = totalFrames;
		this.moveTo(x, y);
	}
	
	public inline function isVisible():Bool {
		return visible;
	}
	
	public function show():Void {
		this.visible = true;
	}
	
	public function hide():Void {
		this.visible = false;
	}
	
	public function goto(frame:Int) {
		throw "Should be overriden";
	}
	
	public inline function moveTo(x:Float, y:Float):Void {
		this.x = x;
		this.y = y;
	}
	
	public function addToDisplayList(root:DisplayObjectContainer, ?x:Null<Float>, ?y:Null<Float>):Void {
		root.addChild(this);
		if (x == null ) x = this.x;
		if (y == null ) y = this.y;
		moveTo(x, y);
	}
}